<?php
include_once 'field.class.php';

class field_schools extends field
{
    public $error;
    private $fomatlist;
    protected $fieldname = '学校列表';

    /**
     * 生成设置项
     * @author menghao
     * @param <string> $data
     * @return <string>
     */
    function settings($data='')
    {
        return '';
    }
    
    


    /**
     * 检查设置项数据
     * @author menghao
     * @param <array> $data 
     */
    function check_settings($data)
    {
       
        return true;
    }

    function check_data($data)
    {
        return parent::check_data($data);
    }
    
    function get_schools()
    {
    	global $db;
    	$list = array();
    	$res = $db->query('select tcode,tname from ' . DB_PRE .'type where parentcode="school" and status=' . STATUS_NORMAL . ' order by listorder desc, inputtime desc');
    	if(is_array($res))
    	{
    		foreach ($res as $v)
    		{
    			$list[$v['tcode']] = $v['tname'];
    		}
    	}
    	return $list;
    }
    
    function set_format()
    {
    	$this->fomatlist = $this->get_schools();
    }
    
    function formate_value($str)
    {
    	$list = array(''=>'未设置');
    	$list = $list + $this->fomatlist;
    	return isset($list[$str]) ? $list[$str] : '未知院校';
    }

    function create_form($value='')
    {
    	global $db;
    	$res = $db->query('select tcode,tname from ' . DB_PRE .'type where parentcode="school" and status=' . STATUS_NORMAL . ' order by listorder desc, inputtime desc');
    	$list = array(''=>'请选择');
    	$list = $list + $this->get_schools();
        $field = $this->field_data['field'];
        $form = form::select($list,"data[$field]", $field, $value);
        return $form;
    }
}
?>